package 字节缓冲流;

import java.io.*;

public class BufferStreamDemo {
    public static void main(String[] args) throws  IOException {
        //字节缓冲输出流：BufferedOutputStream (OutputStream out)
//        FileOutputStream fos=new FileOutputStream("fos.txt");
//        //创建字节缓冲输出流对象
//        BufferedOutputStream bos=new BufferedOutputStream(fos);
          BufferedOutputStream bos=new BufferedOutputStream(new FileOutputStream("fos.txt"));
          //写数据
        bos.write("hello\r\n".getBytes());
        bos.write("world\r\n".getBytes());
        bos.write("java\r\n".getBytes());

          //释放资源
        bos.close();

        //读数据
        BufferedInputStream bis=new BufferedInputStream(new FileInputStream("fos.txt"));
        /*int by;
        while((by=bis.read())!=-1) {
            System.out.print((char) by);
        }*/

        //一次读取一个字节数组的数据
        byte[] bys=new byte[1024];
        int len;
        while((len=bis.read(bys))!=-1){
            System.out.print(new String(bys,0,len));
        }

        bis.close();

    }
}
